package com.base.Queue;

import com.base.comm.CommUrls;
import com.base.helper.WebHelper;
import lombok.extern.log4j.Log4j;
import net.sf.json.JSONObject;

import java.util.Map;
import java.util.concurrent.TimeUnit;

@Log4j
public class DelayPostCallWorker implements Runnable{
    private JSONObject body; //回调的CallBack
    private Map<String,String> param; //回调的参数
    private Integer Time;  //回调的次数

    public DelayPostCallWorker(JSONObject body, Map<String, String> param, Integer time) {
        this.body = body;
        this.param = param;
        Time = time;
    }

    @Override
    public void run() {
        // TODO Auto-generated method stub
        //相关业务逻辑处理  目前只需要URL 别的参数的话暂时不管，以后再加
        String result=null;
        result = WebHelper.doBodyPost(CommUrls.THISSERVER + "callTest/getCallBack", body);
        log.warn("骑士卡话单回调返回结果:"+result);
        if (result==null && Time>0){
            Time--;
            DelayPostCallWorker work = new DelayPostCallWorker(body,null,Time);
            DelayOrderQueueManager manager = DelayOrderQueueManager.getInstance();
            manager.put(work, 3000, TimeUnit.MILLISECONDS);
        }else if (result==null){
            log.error("发送回调信息失败:"+body.toString());
        }
    }
}
